import chartConfig from "./chartConfig";

// 主页设备概况
const getDeviceOption = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: [
        "锅炉",
        "压力容器",
        "电梯",
        "起重机械",
        "场（厂）内专用机动车辆",
        "大型游乐设施",
        "客运索道",
      ],
      data: [0,0,0,0,0,0,0]
    };
  }

  let deviceOption = {
    color: ["#3398DB","#f00000","#3398DB","#3398DB","#3398DB","#3398DB","#3398DB",],
    tooltip: {
      trigger: "axis",
      axisPointer: {
        // 坐标轴指示器，坐标轴触发有效
        type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
      },
    },
    grid: {
      top: "15%",
      left: "5%",
      right: "5%",
      bottom: "0%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: arrs.types,
        axisTick: {
          alignWithLabel: true,
        },
        axisLabel: {
          color: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size,
          interval: 0,
          rotate: 30,
        },
      },
    ],
    yAxis: [
      {
        type: "value",
        name: "设备总数 (电梯数量单位："+arrs.count+")",
        nameTextStyle: {
          color: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size,
          align: 'left'
        },
        axisLabel: {
          color: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size,
        },
        minInterval: 1,
      },
    ],
    series: [
      {
        name: "设备数量",
        type: "bar",
        barWidth: "60%",
        data: arrs.data,
        label: {
          show: true,
          // formatter: "{c}",
          formatter: function (data) {
            // console.log(data);
            if (data.name == '电梯' && data.value > 0) {
              return data.value + "\n"+arrs.count
            }
            return data.value
          },
        },
        itemStyle: {
          normal: {
            color: function(params) {
              var colorlist = ["#3398DB","#3398DB","#f00000","#3398DB","#3398DB","#3398DB","#3398DB",];
              return colorlist[params.dataIndex];
            },
          },
        },
      },
    ],
  };
  return deviceOption;
};

// 主页单位概况
const getUnitOption = (arrs) => {

  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["使用单位", "检验单位", "设计单位", "制造单位", "施工单位", "维保单位"],
      data: [0,0,0,0,0,0]
    };
  }

  let unitOption = {
    grid: {
      top: "5%",
      left: "25%",
      right: "10%",
    },
    tooltip: {
      trigger: "item",
      formatter: "{b}: {c}",
    },
    xAxis: {
      type: "value",
      name: "单位总数",
      nameTextStyle: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
        align: 'right',
        verticalAlign: 'top',
        padding: [3,0,0,0]
      },
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
        margin: 25
      },
      minInterval: 1,
    },
    yAxis: {
      type: "category",
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 4,
        interval: 0,
        // rotate: 30,
        shadowOffsetY: 5,
      },
    },
    series: [
      {
        data: arrs.data,
        type: "bar",
        itemStyle: {
          normal: {
            color: function(params) {
              var colorlist = chartConfig.c_color_arr_6;
              return colorlist[params.dataIndex];
            },
            barBorderRadius: [0, 5, 5, 0],
          },
        },
        barCategoryGap: "50%",
        label: {
          show: true,
          formatter: function (data) {
            // console.log(data);
            if (data.name == '使用单位' && data.value > 0) {
              return data.value + " "+arrs.count
            }
            return data.value
          },
        },
      },
    ],
  };
  return unitOption;
};

// 主页人员概况
const getPersonOption = (arrs) => {

  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["检验单位", "监察执法", "作业人员", "专家"],
      data: [0,0,0,0]
    };
  }

  let personOption = {
    // "监察人员", "作业人员", "专家人员"
    grid: {
      top: "5%",
      left: "5%",
      right: "20%",
    },
    tooltip: {
      trigger: "item",
      formatter: "{b}: {c}",
    },
    xAxis: {
      type: "value",
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
      },
      inverse: true,
      minInterval: 1
    },
    yAxis: {
      type: "category",
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 4,
      },
      position: "right",
    },
    series: [
      {
        data: arrs.data,
        type: "bar",
        itemStyle: {
          normal: {
            color: function(params) {
              var colorlist = chartConfig.c_color_arr_4;
              return colorlist[params.dataIndex];
            },
            shadowColor: "rgba(255, 255, 255, 0.2)",
            shadowBlur: 10,
          },
        },
        barCategoryGap: "50%",
        label: {
          show: true,
        },
      },
    ],
  };
  return personOption;
};

// 主页设备年度数量趋势
const getTrendOption = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      Ylist: ["2016", "2017", "2018", "2019", "2020"],
      devANumlist: [0, 0, 0, 0, 0],
      devAddNumlist: [0, 0, 0, 0, 0],
      devDelNumlist: [0, 0, 0, 0, 0],
    };
  }
  let trendOption = {
    color: ["#37a2da", "#67e0e3", "#ffdb5c"],
    legend: {
      show: true,
      data: ["设备总数", "设备新增", "设备注销"],
      top: "10%",
      left: "10%",
      textStyle: {
        fontFamily: "Arial",
        fontSize: chartConfig.c_font_size + 2,
        fill: chartConfig.c_font_color,
      },
    },
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    xAxis: {
      data: arrs.Ylist,
      axisLabel: {
        style: {
          fill: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size,
          rotate: 15,
        },
      },
    },
    yAxis: {
      data: "value",
      axisLabel: {
        style: {
          fill: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size,
          rotate: 0,
        },
      },
      min: 0
    },
    series: [
      {
        name: "设备总数",
        data: arrs.devANumlist,
        type: "bar",
        shapeType: "leftEchelon",
        label: {
          show: true,
        },
      },
      {
        name: "设备新增",
        data: arrs.devAddNumlist,
        type: "bar",
        shapeType: "normal",
        label: {
          show: true,
        },
      },
      {
        name: "设备注销",
        data: arrs.devDelNumlist,
        type: "bar",
        shapeType: "rightEchelon",
        label: {
          show: true,
        },
      },
    ],
  };
  return trendOption;
};

const getTestOption = (data) => {
  let testOption = {
    test: "测试用的DATA: " + data,
  };
  return testOption;
};

export {
  getDeviceOption,
  getUnitOption,
  getPersonOption,
  getTrendOption,
  getTestOption,
};

// export default indexChartOption;
